<?php defined('SYSPATH') or die('No direct script access.');
/*
 * 装修网运营管理默认入口页控制器
 */
class Controller_Admin_Welcome extends Controller_Template {

	public function __construct ($req, $res)
	{
		parent::__construct ($req, $res);
		$this->template = 'smarty:admin/welcome/default';
	}

	public function action_index()
	{
        $this->request->redirect('/message');
	}

	private function url_login_ru ()
	{
		
		$re_url	= $this->request->referrer();

		$user_info	= User::current_user_info();
		
		if(empty($re_url) )
			$re_url	= 'http://'.Site::domain('manager').'/';

		$url = $this->request->url(array(
					'controller' => 'passport', 
					'action'     => 'login_callback', 
				), 'http');
		$url .= '?referer=' . rawurlencode($re_url);
		
		return $url;
	}

	public function action_widget ($type)
	{
		$this->template->set_filename('smarty:widget/admin/behaviorlist');
		if ($type == 'today_behavior')
		{
			$behavior = user_behavior::today();
			$member_url = 'http://'.Site::domain('member');
			$IM_info  = Kohana::config('shopinfo.status1');
			$this->template->set('behavior_list', $behavior);
			$this->template->set('member_url', $member_url);
			$this->template->set('IM_info',$IM_info);
		}
		if ($type == 'user_behavior')
		{
			$uid      = $this->request->query('uid');
			$behavior = user_behavior::behavior($uid);
			$member_url = 'http://'.Site::domain('member');
			$IM_info  = Kohana::config('shopinfo.status1');
			$this->template->set('behavior_list', $behavior);
			$this->template->set('member_url', $member_url);
			$this->template->set('IM_info',$IM_info);
		}
	}

	/*
	 * 运营后台操作菜单
	 */
	public function action_menus ()
	{
		$this->template->set_filename('smarty:admin/menu/default');
		$this->template->set('menu', Menu::load('admin'));
	}

	/**
	 * 上线操作
	 */
	public function action_online(){
// 		$file = APPPATH.'logs/2012/09/online.lock';
// 		if(file_exists($file)){
// 			$this->request->redirect('http://'.site::domain('member'));
// 		}

		if($_POST['online']){
// 			@file_put_contents($file, '',FILE_APPEND);
			$this->request->redirect('http://'.site::domain('member'));
		}
		$this->template->set_filename('smarty:admin/welcome/online');
	}
	
} // End Welcome
